package com.adulcimer.core.config;

import com.adulcimer.core.common.ChatWebSocketInterceptor;
import com.adulcimer.core.handler.WebSocketChatHandler;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author Simon
 * @create 2025/7/18
 * @Description
 **/
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private WebSocketChatHandler webSocketChatHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketChatHandler, "/api/websocket")
                .addInterceptors(new ChatWebSocketInterceptor()) //注册拦截器，用来拿参数
                .setAllowedOrigins("*");
    }
}
